﻿//------------------------------------------------------------------------------
// System Name:    Customer Service Platform
// Component:      CIS Overseas DepartmentManagement
// Created By:     Samara Jiang (samaraj@wicresoft.com)
// Created Date:   2011-1-30
//------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASBCC.Business;
using ASBCC.Business.CIS;
using ASBCC.Database.EntityFramework;

namespace BEGDC.CC.Web.CIS2.Overseas.Admin
{
    /// <summary>
    ///  CIS Overseas DepartmentManagement
    /// </summary>
    public partial class DepartmentManagement : EntityPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected override EntityDataSource EntitySource
        {
            get { return this.edsDepartment; }
        }

        protected override TextBox EntitySearchTxt
        {
            get { return this.SearchText; }
        }

        protected override Button EntityAddBtn
        {
            get { return this.Addbtn; }
        }


        protected override Button EntityClearBtn
        {
            get { return this.Cleanbtn; }
        }

        protected override GridView EntityGrid
        {
            get { return this.gvDepartment; }
        }

        protected override DetailsView EntityDetails
        {
            get { return this.dvDepartment; }
        }

        protected override void OnEntityDisabling(int entityKey)
        {
            DepartmentManagementHelper.SetDepartmentDisabled(entityKey);
            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CIO, "CustomerDepartment disabled. id=" + entityKey + "; name=" + DepartmentManagementHelper.getName(entityKey));
        }

        protected override string GetEntityWhereExpression(string keyword)
        {
            return "(it.Name like N'%" + keyword + "%'"
                 + " or it.Description like N'%" + keyword + "%')";
        }

        protected override void OnEntityInserting(EntityDataSourceChangingEventArgs e)
        {

        }

        protected override void OnEntityUpdating(EntityDataSourceChangingEventArgs e)
        {

        }

       

        protected void edsDepartment_Inserted(object sender, EntityDataSourceChangedEventArgs e)
        {
            var dc = e.Context;
            var department = e.Entity as CustomerDepartment;

            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CIO, "Department inserted. id=" + department.DepartmentID + "; name=" + department.Name + "; description="+department.Description);
        }

        protected void edsDepartment_Updated(object sender, EntityDataSourceChangedEventArgs e)
        {
            var dc = e.Context;
            var department = e.Entity as CustomerDepartment;

            GlobalHelper.LogOperation(this.User.Identity.Name, SystemModule.CIO, "Department updated. id=" + department.DepartmentID + "; name=" + department.Name + "; description="+department.Description);
        }

        protected void Searchbtn_Click(object sender, EventArgs e)
        {
            gvDepartment.PageIndex = 0;
        }

    }
}
